package xxl.ioc.typedescriptions 
{
	import flash.utils.Dictionary;
	import xxl.ioc.dependencyproviders.IDependencyProvider;
	import xxl.ioc.Injector;
	import xxl.ioc.utils.IOCInternal;
	/**
	 * ...
	 * @author XXL
	 */
	public class PropertyInjectionPoint extends InjectionPoint 
	{
		private var _propertyName:String;
		private var _mappingId:String;
		private var _optional:Boolean;
		
		public function PropertyInjectionPoint(mappingId:String, propertyName:String, optional:Boolean, injectParameters:Dictionary) 
		{
			_propertyName = propertyName;
			_mappingId = mappingId;
			_optional = optional;
			this.injectParameters = injectParameters;
		}
		
		override public function applyInjection(target:Object, targetType:Class, injector:Injector):void 
		{
			const provider:IDependencyProvider = injector.IOCInternal::getProvider(_mappingId);
			if (!provider)
			{
				if (_optional)
				{
					return;
				}
				throw new Error("PropertyInjectionPoint");
			}
			target[_propertyName] = provider.apply(targetType, injector, injectParameters);
		}
		
	}

}